import { AxiosRequestConfig } from 'axios';
import request from '@/utils/request';

/*************************************接入设备********************************/
/**
 * 查询设备管理列表
 */
export const listDevice = (params: any) => {
  return request({
    url: '/device/list',
    method: 'get',
    params,
  });
};

/**
 * 查询设备管理详细
 */
export const getDevice = (deviceId: any) => {
  return request({
    url: `/device/${deviceId}`,
    method: 'get',
  });
};

/**
 * 新增设备管理
 */
export const addDevice = (data: any) => {
  return request({
    url: '/device',
    method: 'post',
    data,
  });
};

/**
 * 修改设备管理
 */
export const updateDevice = (data: any) => {
  return request({
    url: '/device',
    method: 'put',
    data,
  });
};

/**
 * 删除设备管理
 */
export const delDevice = (deviceId: any) => {
  return request({
    url: `/device/${deviceId}`,
    method: 'delete',
  });
};

/**
 * 删除全部设备管理
 */
export const delAllDevice = () => {
  return request({
    url: '/device/deleteAll',
    method: 'delete',
  });
};

/**
 * 查询设备参数
 */
export const getDeviceParam = (deviceId: any) => {
  return request({
    url: `/device/deviceParam/${deviceId}`,
    method: 'get',
  });
};

/**
 * 查询接入规则
 */
export const getDeviceRules = (params: any) => {
  return request({
    url: '/accessRules/list',
    method: 'get',
    params,
  });
};

/**
 * 新增接入规则
 */
export const addDeviceRules = (data: any) => {
  return request({
    url: '/accessRules/add',
    method: 'post',
    data,
  });
};

/**
 * 修改接入规则
 */
export const updateDeviceRules = (data: any) => {
  return request({
    url: '/accessRules/update',
    method: 'put',
    data,
  });
};

/**
 * 删除接入规则
 */
export const delDeviceRules = (deviceId: any) => {
  return request({
    url: `/accessRules/del?ids=${deviceId}`,
    method: 'delete',
  });
};

/**
 * 查询设备型号
 */
export const getModel = (params?: any) => {
  return request({
    url: '/deviceMode/modelInfo',
    method: 'get',
    params,
  });
};

/**
 * 查询安装详情
 * @param params
 * @returns
 */
export function getInstallationDetail(params: any) {
  return request({
    url: '/device/getInstallationDetailByCode',
    method: 'get',
    params,
  });
}

export function getSIMCardType(params: any) {
  return request({
    url: '/sim/checkCardType',
    method: 'get',
    params,
  });
}
export function getAlyCardDetail(params: any) {
  return request({
    url: '/sim/aliyun/getCardDetail',
    method: 'get',
    params,
  });
}

// 调用阿里云API恢复单个SIM卡的功能
export function getAlyResumeCard(data: any) {
  return request({
    url: '/sim/aliyun/resumeSingleCard',
    method: 'post',
    data,
  });
}

// 重新绑定和恢复单卡状态的方法
export function getAlyRebindCard(data: any) {
  return request({
    url: '/sim/aliyun/rebindResumeSingleCard',
    method: 'POST',
    data,
  });
}

// 调用LXAPI获取SIM卡流量信息
export function getLxFlowInfo(params: any) {
  return request({
    url: '/sim/lx/getCardFlowInfo',
    method: 'get',
    params,
  });
}

// 调用LXAPI获取SIM卡流量信息
export function getLxCardDetail(params: any) {
  return request({
    url: '/sim/lx/getCardDetail',
    method: 'get',
    params,
  });
}

// 调用LXAPI停止SIM卡的服务
export function getLxStopSingleCard(data: any) {
  return request({
    url: '/sim/lx/stopSingleCard',
    method: 'post',
    data,
  });
}

// 调用LX服务恢复单卡状态
export function getLxResumeSingleCard(data: any) {
  return request({
    url: '/sim/lx/resumeSingleCard',
    method: 'post',
    data,
  });
}

// 调用LX服务计费组统计查询
export function getLxPoolStatistics(params: any) {
  return request({
    url: '/sim/lx/poolStatistics',
    method: 'get',
    params,
  });
}

// 调用阿里云API停止单个SIM卡的服务
export function getAlyStopCard(data: any) {
  return request({
    url: '/sim/aliyun/stopSingleCard',
    method: 'post',
    data,
  });
}

// 获取阿里云SIM卡流量信息
export function getAlyFlowInfo(params: any) {
  return request({
    url: '/sim/aliyun/getCardFlowInfo',
    method: 'get',
    params,
  });
}

// 网络
export function getNetworkWaveform(params: any) {
  return request({
    url: '/deviceRealTime/getNetworkWaveform',
    method: 'get',
    params,
  });
}

// 网络延迟波形图
export function getTimeDelayWaveform(params: any) {
  return request({
    url: '/deviceRealTime/getTimeDelayWaveform',
    method: 'get',
    params,
  });
}

// 获取阿里云凭证池统计信息
export function getAlyPoolStatistics(params: any) {
  return request({
    url: '/sim/aliyun/getCredentialPoolStatistics',
    method: 'get',
    params,
  });
}
// 性能
export function getUseRateWaveform(params: any) {
  return request({
    url: '/deviceRealTime/getUseRateWaveform',
    method: 'get',
    params,
  });
}

// 传感器
export function getSensorWaveform(params: any) {
  return request({
    url: '/deviceRealTime/getSensorWaveform',
    method: 'get',
    params,
  });
}

//电压
export function getVoltageWaveform(params: any) {
  return request({
    url: '/deviceRealTime/getVoltageWaveform',
    method: 'get',
    params,
  });
}

/**
 * 查询配置日志信息
 * @param code
 * @param params
 * @returns
 */
export function getDeviceMqttConfig(code: string, params: any) {
  return request({
    url: '/device/getDeviceMqttConfig/' + code,
    method: 'get',
    params,
  });
}

//查询日志信息
export function downloadLogFile(data: any) {
  return request({
    url: '/file/downloadLogFile1',
    method: 'post',
    data: data,
  });
}

// 设备自检日志
export function systemCheckLog(params: any) {
  return request({
    url: '/systemCheckLog/list',
    method: 'get',
    params,
  });
}

/**
 * 查询气象日志
 * @param params
 * @returns
 */
export function getWeatherWarningList(params: any) {
  return request({
    url: '/weatherWarning/deviceList',
    method: 'get',
    params,
  });
}
/**
 * 查询气象日志
 * @param params
 * @returns
 */
export function getDeviceWeatherMessageList(params: any) {
  return request({
    url: '/weatherWarning/getDeviceWeatherMessageList',
    method: 'get',
    params,
  });
}

export function getQuickReportMessage(params: any) {
  return request({
    url: '/quickReportMessage/list',
    method: 'get',
    params,
  });
}

export function getDeviceQuickReportList(params: any) {
  return request({
    url: '/quickReportMessage/getDeviceQuickReportMessageList',
    method: 'get',
    params,
  });
}

export function getWarningMessage(data: any) {
  const { pageNum, pageSize } = data;
  let postdata = {
    ...data,
  };
  delete postdata.pageNum;
  delete postdata.pageSize;
  return request({
    url: '/warningMessage/list' + `?pageNum=${pageNum}&pageSize=${pageSize}`,
    method: 'post',
    data: postdata,
  });
}
export function getDeviceWarningList(params: any) {
  return request({
    url: '/warningMessage/getDeviceWarningMessageList',
    method: 'get',
    params,
  });
}

export function getListByEewId(params: any) {
  return request({
    url: '/warningMessage/getListByEewId',
    method: 'get',
    params,
  });
}
/*************************************设备型号管理********************************/
/**
 * 查询设备型号列表
 */
export const listInfo = (params: any) => {
  return request({
    url: '/deviceMode/list',
    method: 'get',
    params,
  });
};

/**
 * 查询设备型号详细
 */
export const getInfo = (modelId: any) => {
  return request({
    url: `/deviceMode/${modelId}`,
    method: 'get',
  });
};

/**
 * 新增设备型号
 */
export const addInfo = (data: any) => {
  return request({
    url: '/deviceMode',
    method: 'post',
    data,
  });
};

/**
 * 修改设备型号
 */
export const updateInfo = (data: any) => {
  return request({
    url: '/deviceMode',
    method: 'put',
    data,
  });
};

/**
 * 删除设备型号
 */
export const delInfo = (modelId: any) => {
  return request({
    url: `/deviceMode/${modelId}`,
    method: 'delete',
  });
};

/*************************************设备总览********************************/
/**
 * 查询设备管理列表
 */
export const listAllDevice = (params: any) => {
  return request({
    url: '/device/totalList',
    method: 'get',
    params,
  });
};

/**
 * 获取地区下拉树结构列表
 * @param deviceIds
 * @returns
 */
export const chinaArea = (params: any) => {
  return request({
    url: '/util/getChinaareaTree',
    method: 'get',
    params,
  });
};
/**
 * 删除设备
 */
export const deviceDelete = (deviceIds: any) => {
  return request({
    url: `/device/${deviceIds}`,
    method: 'delete',
  });
};

/**
 * 重启
 */
export const deviceRestart = (data: any) => {
  return request({
    url: '/device/restart',
    method: 'POST',
    data,
  });
};

/**
 * 断开
 */
export const disconnectDevice = (codes: any) => {
  return request({
    url: `/device/disconnectDevice/${codes}`,
    method: 'get',
  });
};

/**
 * 批量清空设备日志
 */
export const deleteTdData = (data: any) => {
  return request({
    url: '/device/deleteTdData',
    method: 'post',
    data,
  });
};

/**
 * 导出设备信息
 */
export const exportDevice = (data: any) => {
  return request({
    url: '/device/export',
    method: 'post',
    data,
    responseType: 'blob',
  });
};

/**
 * 运行模式配置
 */
export const getRunningModeConfig = (code: any) => {
  return request({
    url: `/device/getRunningModeConifg/${code}`,
    method: 'GET',
  });
};

export const updateRunningModeConfig = (data: any) => {
  return request({
    url: '/device/updateRunningModeConifg',
    method: 'post',
    data,
  });
};

/**
 * 桌面主题配置
 */
export const getThemeConfig = (code: any) => {
  return request({
    url: `/device/getThemeConfig/${code}`,
    method: 'GET',
  });
};

export const updateThemeConfig = (data: any) => {
  return request({
    url: '/device/updateThemeConfig',
    method: 'post',
    data,
  });
};

/**
 * 预警服务
 */
export const getMqttConfig = (code: any) => {
  return request({
    url: `/device/getMqttConfig/${code}`,
    method: 'GET',
  });
};

export const getMqttConfig_2 = (code: any) => {
  return request({
    url: `/device/getTrConfig/${code}`,
    method: 'GET',
  });
};

export const getMqttInfo = (code: any) => {
  return request({
    url: `/registerPublish/getMqttInfo/${code}`,
    method: 'GET',
  });
};

export const updateMqttConfig = (data: any) => {
  return request({
    url: '/device/updateMqttConfig',
    method: 'POST',
    data,
  });
};

export const updateMqttConfig_2 = (data: any) => {
  return request({
    url: '/device/updateTrConfig',
    method: 'POST',
    data,
  });
};

// 历史服务配置记录
export const historyMqtt = (params: any) => {
  return request({
    url: '/historyMqttConfig/list',
    method: 'GET',
    params,
  });
};

// 历史服务配置更新
export const mqttHistoryUpdate = (code: any) => {
  return request({
    url: `/device/mqttHistoryUpdate/${code}`,
    method: 'GET',
  });
};

// mqtt注册
export const registerMqtt = (params: any) => {
  return request({
    url: '/mqtt/tm_register',
    method: 'get',
    params,
    timeout: 180000,
  });
};

// mqtt授权
export const authorizeMqtt = (params: any) => {
  return request({
    url: '/mqtt/tm_authorize',
    method: 'get',
    params,
    timeout: 180000,
  });
};

/**
 * 管理服务
 */
export const getNettyConfig = (code: any) => {
  return request({
    url: `/device/getNettyConfig/${code}`,
    method: 'GET',
  });
};

export const updateNettyConfig = (data: any) => {
  return request({
    url: '/device/updateNettyConfig',
    method: 'POST',
    data,
  });
};

/**
 * 文件服务
 */
export const getFileConfig = (code: any) => {
  return request({
    url: `/device/getFileConfig/${code}`,
    method: 'GET',
  });
};

export const updateFileConfig = (data: any) => {
  return request({
    url: '/device/updateFileConfig',
    method: 'POST',
    data,
  });
};

// 历史服务配置记录
export const historyFile = (params: any) => {
  return request({
    url: 'historyFileConfig/list',
    method: 'GET',
    params,
  });
};
// 历史服务配置更新
export const fileHistoryUpdate = (code: any) => {
  return request({
    url: `/device/fileHistoryUpdate/${code}`,
    method: 'GET',
  });
};

/**
 * 定位配置
 */
export const getGpsConfig = (code: any) => {
  return request({
    url: `/device/getGpsConfig/${code}`,
    method: 'GET',
  });
};

export const updateGpsConfig = (data: any) => {
  return request({
    url: '/device/updateGpsConfig',
    method: 'POST',
    data,
  });
};

/**
 * 对时配置
 */
export const getNtpConfig = (code: any) => {
  return request({
    url: `/device/getNtpConfig/${code}`,
    method: 'GET',
  });
};

export const updateNtpConfig = (data: any) => {
  return request({
    url: '/device/updateNtpConfig',
    method: 'POST',
    data,
  });
};

/**
 * 气象服务
 */
export const getWeatherConfig = (code: any) => {
  return request({
    url: `/device/getWeatherConfig/${code}`,
    method: 'GET',
  });
};
export const updateWeatherConfig = (data: any) => {
  return request({
    url: '/device/updateWeatherConfig',
    method: 'POST',
    data,
  });
};

/**
 * 预警配置
 */
export const getWarnConfig = (code: any) => {
  return request({
    url: `/device/getWarnConfig/${code}`,
    method: 'GET',
  });
};

export const updateWarnConfig = (data: any) => {
  return request({
    url: '/device/updateWarnConfig',
    method: 'POST',
    data,
  });
};

export const getWarnConfig_2 = (code: any) => {
  return request({
    url: `/device/newGetWarnConfig/${code}`,
    method: 'GET',
  });
};

export const updateWarnConfig_2 = (data: any) => {
  return request({
    url: '/device/newUpdateWarnConfig',
    method: 'POST',
    data,
  });
};

/**
 * 上传证书
 */
export const importCertGen = (data: any, config: AxiosRequestConfig<any>) => {
  return request({
    url: '/device/importCertGen',
    method: 'post',
    data,
    ...config,
  });
};

/**
 * 速报服务
 */
export const getReportConfig = (code: any) => {
  return request({
    url: `/device/getReportConfig/${code}`,
    method: 'GET',
  });
};

export const updateReportConfig = (data: any) => {
  return request({
    url: '/device/updateReportConfig',
    method: 'POST',
    data,
  });
};

/**
 * 音量配置
 */
export const getVolumeConfig = (code: any) => {
  return request({
    url: `/device/getVolumeConfig/${code}`,
    method: 'GET',
  });
};

export const updateVolumeConfig = (data: any) => {
  return request({
    url: '/device/updateVolumeConfig',
    method: 'POST',
    data,
  });
};

/**
 * 屏显配置
 */
export const getEnergyConfig = (code: any) => {
  return request({
    url: `/device/getEnergyConfig/${code}`,
    method: 'GET',
  });
};

export const updateEnergyConfig = (data: any) => {
  return request({
    url: '/device/updateEnergyConfig',
    method: 'POST',
    data,
  });
};

/**
 * 设备配置
 */
export const getDeviceConfig = (code: any) => {
  return request({
    url: `/device/getDeviceConfig/${code}`,
    method: 'GET',
  });
};

export const updateDeviceConfig = (data: any) => {
  return request({
    url: '/device/updateDeviceConfig',
    method: 'POST',
    data,
  });
};

// 视频配置
export const getVideoConfig = (code: any) => {
  return request({
    url: `/device/getVideoConfig/${code}`,
    method: 'GET',
  });
};
export const updateVideoConfig = (data: any) => {
  return request({
    url: '/device/updateVideoConfig',
    method: 'POST',
    data,
  });
};
// 以太网配置
export const getEthernetConfig = (code: any) => {
  return request({
    url: `/device/getEthernetConfig/${code}`,
    method: 'GET',
  });
};
export const updateEthernetConfig = (data: any) => {
  return request({
    url: '/device/updateEthernetConfig',
    method: 'post',
    data,
  });
};

/**
 * 网络配置
 */
export const getNetworkCheck = (code: any) => {
  return request({
    url: `/device/getNetworkCheck/${code}`,
    method: 'GET',
  });
};

export const networkCheck = (data: any) => {
  return request({
    url: '/device/networkCheck',
    method: 'post',
    data,
  });
};

/**
 * GPIO配置
 */
export const getGpioControlConfig = (code: any) => {
  return request({
    url: `/device/getGpioControlConfig/${code}`,
    method: 'GET',
  });
};

export const updateGpioControlConfig = (data: any) => {
  return request({
    url: '/device/updateGpioControlConfig',
    method: 'post',
    data,
  });
};

/**
 * 快捷操作
 */
export const synchronizeQuickReport = (code: any, count: any) => {
  return request({
    url: `/device/synchronizeQuickReport/${code}/${count}`,
    method: 'GET',
  });
};

export const systemCheck = (code: any) => {
  return request({
    url: `/device/systemCheck/${code}`,
    method: 'get',
  });
};

export const downloadScreenshotFile = (data: any) => {
  return request({
    url: '/file/downloadScreenshotFile1',
    method: 'post',
    data: data,
  });
};

/**
 * 远程操作
 */
export const getrtmpConfig = (code: any) => {
  return request({
    url: `/device/getRtmpConfig/${code}`,
    method: 'GET',
  });
};

export const updatertmpConfig = (data: any) => {
  return request({
    url: '/device/updateRtmpConfig',
    method: 'POST',
    data,
  });
};

export const getRemoteUser = (code: any) => {
  return request({
    url: `/device/getRemoteUser/${code}`,
    method: 'get',
  });
};

export const addRemoteUser = (data: any) => {
  return request({
    url: '/device/addRemoteUser',
    method: 'post',
    data,
  });
};

export const remoteKeyboard = (data: any) => {
  return request({
    url: '/device/remoteKeyboard',
    method: 'post',
    data,
  });
};

/**
 * 文件浏览
 */
export const operationDeviceFile = (data: any) => {
  return request({
    url: '/device/operationDeviceFile',
    method: 'post',
    data,
  });
};

export const downloadDeviceFile = (data: any) => {
  return request({
    url: '/file/downloadDeviceFile',
    method: 'post',
    responseType: 'blob',
    fetchOptions: { noEncoded: true },
    data,
  });
};

/**
 * 无线组网
 */
export const getWirelessConfigList = (code: any) => {
  return request({
    url: `/device/getMeshConfig/${code}`,
    method: 'GET',
  });
};

export const postWirelessConfigList = (data: any) => {
  return request({
    url: '/device/updateMeshConfig',
    method: 'post',
    data,
  });
};

export const onlineDetection = (code: any) => {
  return request({
    url: `/device/onlineDetection/${code}`,
    method: 'GET',
  });
};

export const checkFrequency = (data: any) => {
  return request({
    url: '/device/checkFrequency',
    method: 'post',
    data,
  });
};

// 获取验证码
export const getCheckCode = (params: any) => {
  return request({
    url: '/device/getCheckCode',
    method: 'get',
    params,
  });
};

export const checkVerityCode = (params: any) => {
  return request({
    url: '/device/checkVerityCode',
    method: 'get',
    params,
  });
};

export const deviceTest = (code: any) => {
  return request({
    url: `/device/onlineTest/${code}`,
    method: 'get',
  });
};

/**
 * 烈度计
 */
export const getIntensityMeterConfig = (code: any) => {
  return request({
    url: `/device/getIntensityMeterConfig/${code}`,
    method: 'GET',
  });
};

//更新烈度仪配置
export const postIntensityMeter = (data: any) => {
  return request({
    url: '/device/updateIntensityMeterConfig',
    method: 'post',
    data,
  });
};

export const getIntensityMeterConfig_2 = (code: any) => {
  return request({
    url: `/device/newGetIntensityMeterConfig/${code}`,
    method: 'GET',
  });
};

//更新烈度仪配置
export const postIntensityMeter_2 = (data: any) => {
  return request({
    url: '/device/newUpdateIntensityMeterConfig',
    method: 'post',
    data,
  });
};

/**
 * 品牌管理
 */
export const getBrandConfig = (code: any) => {
  return request({
    url: `/device/getDeviceBrand/${code}`,
    method: 'get',
  });
};
export const updateBrandConfig = (data: any) => {
  return request({
    url: '/device/updateDeviceBrand',
    method: 'post',
    data,
  });
};

/*********************************设备总览-设备详情****************************/
/**
 *基本信息保存
 */
export const updateAllDevice = (data: any) => {
  return request({
    url: '/device/totalDevice',
    method: 'put',
    data,
  });
};

/**
 *设备实时数据
 */
export const getDeviceRealTimeData = (deviceId: any) => {
  return request({
    url: `/device/getDeviceRealTimeData/${deviceId}`,
    method: 'get',
  });
};

// 获取屏幕状态
export const getScreenInfo = (code) => {
  return request({
    url: `/device/getScreenInfo/${code}`,
    method: 'get',
  });
};

// 批量修改设备使用的搜索接口
export const getProjectDeviceMapV8 = (params: any) => {
  return request({
    url: `/project/getProjectDeviceMapV8`,
    method: 'get',
    params,
  });
};

// 数据批量推送 新增或编辑
export const deviceBatchSave = (data: any) => {
  return request({
    url: '/device/batch/save',
    method: 'post',
    data,
  });
};

// 数据批量推送 列表
export const deviceBatchList = (params: any) => {
  return request({
    url: '/device/batch/list',
    method: 'get',
    params,
  });
};

// 数据批量推送 删除
export const deviceBatchDelete = (id: any) => {
  return request({
    url: `/device/batch/delete/${id.join()}`,
    method: 'post',
  });
};

// 数据批量推送 审核
export const deviceBatchDeviceBatchPass = (id: any) => {
  return request({
    url: `/device/batch/deviceBatchPass/${id}`,
    method: 'post',
  });
};

// 数据批量推送 详情
export const deviceBatchDetail = (id: any) => {
  return request({
    url: `/device/batch/detail/${id}`,
    method: 'get',
  });
};

// 批量修改设备使用的搜索已选中接口
export const getProjectDeviceMapV8ForDevice = (data: any) => {
  return request({
    url: '/project/getProjectDeviceMapV8ForDevice',
    method: 'post',
    data,
  });
};

// 日程管理-新增
export const reqScheduleManagementAdd = (data: any) => {
  return request({
    url: '/device/addEquipmentScheduleDay',
    method: 'post',
    data,
  });
};

// 日程管理-按天查日程数据
export const reqScheduleManagementDay = (params: any) => {
  return request({
    url: '/device/getEquipmentScheduleDay',
    method: 'get',
    params,
  });
};

// 日程管理-修改
export const reqScheduleManagementUpdate = (data: any) => {
  return request({
    url: '/device/updateEquipmentScheduleDay',
    method: 'post',
    data,
  });
};

// 日程管理-删除
export const reqScheduleManagementDel = (data: any) => {
  return request({
    url: '/device/deleteEquipmentScheduleDay',
    method: 'post',
    data,
  });
};

// 日程管理-点信息
export const reqScheduleManagementDot = (params: any) => {
  return request({
    url: '/device/getEquipmentSchedulePoint',
    method: 'get',
    params,
  });
};

// 多媒体资料
export const reqMultimediaDataAll = (params: any) => {
  return request({
    url: '/device/getMultimediaCatalogue',
    method: 'get',
    params,
  });
};

// 大文件下载 -----3个接口
// 1获取文件的fileId
export const reqDownloadFileByPath = (params: any) => {
  return request({
    url: '/device/downloadFileByPath',
    method: 'get',
    params,
  });
};

// 2 每3秒调一下下载文件的进度
export const reqFileDownloadRateByFileId = (params: any) => {
  return request({
    url: '/device/getFileDownloadRateByFileId',
    method: 'get',
    params,
  });
};

// 3下文件
export const reqFileByFileId = (params: any) => {
  return request({
    url: '/device/getFileByFileId',
    method: 'get',
    params,
    responseType: 'blob',
  });
};
